package  org.fantasy.cpp.core.pojo;

import java.util.List;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Table;

import  org.fantasy.cpp.core.annotation.Field;

@Table("QUERY_ITEM")
public class QueryItem {

	/**
	 * 输入框
	 */
	public static final int TYPE_INPUT = 1;

	/**
	 * 下拉列表框
	 */
	public static final int TYPE_SELECT = 2;

	/**
	 * 复选框
	 */
	public static final int TYPE_CHECKBOX = 3;

	/**
	 * 单选框
	 */
	public static final int TYPE_RADIO = 4;

	/**
	 * 树
	 */
	public static final int TYPE_TREE = 5;

	@Id
	@Column("item_id")
	@Field(desc = "查询条件id", nullable = false)
	private Long itemId;

	@Column("item_type_id")
	@Field(desc = "条件类型id", nullable = true)
	private Long itemTypeId;

	@Column("query_id")
	@Field(desc = "查询id", nullable = true)
	private Long queryId;

	@Column("item_name")
	@Field(desc = "查询条件名称", nullable = false, maxlenth = 128)
	private String itemName;

	@Column("item_code")
	@Field(desc = "输入条件名称", nullable = false, maxlenth = 128)
	private String itemCode;

	@Column("item_check")
	@Field(desc = "输入条件必选", nullable = false)
	private Long itemCheck;

	@Column("item_format")
	@Field(desc = "输入条件格式", nullable = true, maxlenth = 128)
	private String itemFormat;

	@Column("def_value")
	@Field(desc = "默认值", nullable = true, maxlenth = 128)
	private String defValue;

	@Column("css_style")
	@Field(desc = "样式style", nullable = true, maxlenth = 128)
	private String cssStyle;

	@Column("css_class")
	@Field(desc = "样式css", nullable = true, maxlenth = 128)
	private String cssClass;

	@Column("class_name")
	@Field(desc = "渲染类", nullable = false, maxlenth = 128)
	private String className;

	@Column("auto_query")
	@Field(desc = "自动查询", nullable = false)
	private Long autoQuery;

	@Column("state")
	@Field(desc = "状态", nullable = false, maxlenth = 8)
	private String state;

	public Long getItemId() {
		return itemId;
	}

	public void setItemId(Long itemId) {
		this.itemId = itemId;
	}

	public Long getItemTypeId() {
		return itemTypeId;
	}

	public void setItemTypeId(Long itemTypeId) {
		this.itemTypeId = itemTypeId;
	}

	public Long getQueryId() {
		return queryId;
	}

	public void setQueryId(Long queryId) {
		this.queryId = queryId;
	}

	public String getItemName() {
		return itemName;
	}

	public void setItemName(String itemName) {
		this.itemName = itemName;
	}

	public String getItemCode() {
		return itemCode;
	}

	public void setItemCode(String itemCode) {
		this.itemCode = itemCode;
	}

	public Long getItemCheck() {
		return itemCheck;
	}

	public void setItemCheck(Long itemCheck) {
		this.itemCheck = itemCheck;
	}

	public String getItemFormat() {
		return itemFormat;
	}

	public void setItemFormat(String itemFormat) {
		this.itemFormat = itemFormat;
	}

	public String getDefValue() {
		return defValue;
	}

	public void setDefValue(String defValue) {
		this.defValue = defValue;
	}

	public String getCssStyle() {
		return cssStyle;
	}

	public void setCssStyle(String cssStyle) {
		this.cssStyle = cssStyle;
	}

	public String getCssClass() {
		return cssClass;
	}

	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	/**
	 * 数据源信息
	 */
	private QueryConfig queryConfig;

	/**
	 * 源数据
	 */
	private Object source;

	/**
	 * 扩展属性
	 */
	private List<ItemAttr> attrs;

	public Object getSource() {
		return source;
	}

	public void setSource(Object source) {
		this.source = source;
	}

	public List<ItemAttr> getAttrs() {
		return attrs;
	}

	public void setAttrs(List<ItemAttr> attrs) {
		this.attrs = attrs;
	}

	public String getAttr(String code) {
		for (ItemAttr attr : attrs) {
			if (code.equals(attr.getAttrCode())) {
				return attr.getAttrValue();
			}
		}
		return "";
	}

	public QueryConfig getQueryConfig() {
		return queryConfig;
	}

	public void setQueryConfig(QueryConfig queryConfig) {
		this.queryConfig = queryConfig;
	}

	public Long getAutoQuery() {
		return autoQuery;
	}

	public void setAutoQuery(Long autoQuery) {
		this.autoQuery = autoQuery;
	}

	@Override
	public String toString() {
		return String.valueOf(itemId);
	}
}